﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using EHTWebsite.Code;

/// <summary>
/// Author: toanvt
/// CreatedDate: 12/12/2011
/// Description: quản lý thông tin liên hệ
/// </summary>
public partial class Administrator_AdminContacts : System.Web.UI.Page
{
    private Int32 pageIndex = 1;
    private Int32 pageSize = 10;
    private Int32 totalRecord;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            pageIndex = Int32.Parse(Request.QueryString["PageIndex"].ToString());
        }
        catch (Exception)
        {
            pageIndex = 1;
        }

        pageSize = this.PaggingControl1.PageSize;

        if (!Page.IsPostBack)
            LoadContacts();
    }
    
    /// <summary>
    /// Author: toanvt
    /// CreatedDate: 12/12/2011
    /// Description: Lấy danh sách thông tin liên hệ
    /// </summary>
    private void LoadContacts()
    {
        rpLienHes.DataSource = LienHeProvider.GetLienHes(pageIndex, pageSize, out totalRecord);
        rpLienHes.DataBind();

        this.PaggingControl1.PageIndex = pageIndex;
        this.PaggingControl1.TotalRecord = totalRecord;
        this.PaggingControl1.PageURL = "AdminContacts.aspx";
    }

    protected void rpLienHes_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        String cmdName = e.CommandName;
        Int32 maLH = Int32.Parse(e.CommandArgument.ToString());
        LoadContacts();
        if (cmdName.ToLower() == "delete1")
        {
            LienHeProvider.DeleteLienHeByLienHeID(maLH);
            LoadContacts();
        }

    }

    protected void rpLienHes_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Label lbStatus = (Label)e.Item.FindControl("lbStatus");
        Label lbTrangThaiDoc = (Label)e.Item.FindControl("lbTrangThaiDoc");
        if (lbTrangThaiDoc != null)
        {
            // Nếu TrangThaiDoc=0 --> Hiện là Chưa xem, TrangThaiDoc=1 --> Hiện là đã xem.
            if (string.IsNullOrEmpty(lbStatus.Text) == false)
            {
                if (Boolean.Parse(lbStatus.Text))
                {
                    lbTrangThaiDoc.Text = "Đã xem";
                }
                else
                {
                    lbTrangThaiDoc.Text = "Chưa Xem";
                }
            }
            else
            {
                lbTrangThaiDoc.Text = "Chưa Xem";
            }
        }
    }
}
